import { Injectable } from '@angular/core';
import { EntityConfig } from '../../core/entity-config.types';
import { SupplierDto } from '../../proxy/joy/erp/basic-archives/suppliers';
import { DatePipe } from '@angular/common';
import { LocalizationService } from '@abp/ng.core';

@Injectable({
  providedIn: 'root'
})
export class SupplierConfigService {
  private datePipe = new DatePipe('zh-CN');

  constructor(private localization: LocalizationService) {}

  getConfig(): EntityConfig {
    return {
      entityType: 'Joy.Erp.BasicArchives.Suppliers.Supplier',
      propertys: [
        {
          name: 'Code',
          key: 'code',
          type: 'string',
          field: (item: SupplierDto) => item.code,
          width: 200,
          show: true,
          order: 0,
          fixed: 0
        },      
        {
          name: 'Name',
          key: 'name',
          type: 'string',
          field: (item: SupplierDto) => item.name,
          width: 200,
          show: true,
          order: 1,
          fixed: 0
        },
        {
          name: 'ShortName',
          key: 'shortName',
          type: 'string',
          field: (item: SupplierDto) => item.shortName,
          width: 150,
          show: true,
          order: 2,
          fixed: 0
        },
        {
          name: 'Contact',
          key: 'contact',
          type: 'string',
          field: (item: SupplierDto) => item.contact,
          width: 120,
          show: true,
          order: 3,
          fixed: 0
        },
        {
          name: 'Phone',
          key: 'phone',
          type: 'string',
          field: (item: SupplierDto) => item.phone,
          width: 150,
          show: true,
          order: 4,
          fixed: 0
        },
        {
          name: 'Address',
          key: 'address',
          type: 'string',
          field: (item: SupplierDto) => item.address,
          width: 300,
          show: true,
          order: 5,
          fixed: 0
        },
        {
          name: 'SupplierType',
          key: 'supplierType',
          type: 'string',
          field: (item: SupplierDto) => item.supplierType?.displayName || '',
          width: 150,
          show: true,
          order: 6,
          fixed: 0
        },
        {
          name: 'Operator',
          key: 'operator',
          type: 'string',
          field: (item: SupplierDto) => item.operator?.name || '',
          width: 120,
          show: true,
          order: 7,
          fixed: 0
        },
        {
          name: 'Enabled',
          key: 'enabled',
          type: 'boolean',
          field: (item: SupplierDto) => item.enabled ? '是' : '否',
          width: 80,
          show: true,
          order: 8,
          fixed: 0
        },
        {
          name: 'CreationTime',
          key: 'creationTime',
          type: 'date',
          field: (item: SupplierDto) => this.datePipe.transform(item.creationTime, 'yyyy-MM-dd'),
          width: 150,
          show: true,
          order: 9,
          fixed: 0
        },
      ]
    };
  }

  private l(key: string, ...params: string[]): string {
    return this.localization.instant(key, ...params);
  }
} 